//
//  MyAFNetWorkManager.m
//  BORGWORD
//
//  Created by 张国庆 on 15/11/18.
//  Copyright © 2015年 zgq. All rights reserved.
//

#import "MyAFNetWorkManager.h"
#import "AFNetworkReachabilityManager.h"
#import "AFURLSessionManager.h"
#import "AFHTTPSessionManager.h"
#import "AppDelegate.h"
#import "UIAlertViewControl.h"
#import "borgword_define.h"
#import "AFHTTPRequestOperationManager.h"


static BOOL isFirst = NO;
static BOOL canCHeckNetwork = NO;
@implementation MyAFNetWorkManager

+(void) postWithParam:(NSDictionary *)dict andAction:(NSString*)actionStr finish:(void (^)(NSData *,NSDictionary *obj, NSError *))back{
    //数据拼接
    NSArray *keyArr=[dict allKeys];
    NSString *keyStr;
    if([keyArr count]>0)
    {
        for(NSString *str in keyArr)
        {
            if(keyStr.length<=0)
            {
                if ([[dict valueForKey:str] isKindOfClass:[NSArray class]]) {
                    NSArray *arr = [dict valueForKey:str];
                    keyStr=[NSString stringWithFormat:@"&%@=%@",str,[arr componentsJoinedByString:@","]];
                }else{
                keyStr=[NSString stringWithFormat:@"&%@=%@",str,[dict valueForKey:str]];
                }
            }
            else
            {
                if ([[dict valueForKey:str] isKindOfClass:[NSArray class]]) {
                    NSArray *arr = [dict valueForKey:str];
                    keyStr=[NSString stringWithFormat:@"%@&%@=%@",keyStr,str,[arr componentsJoinedByString:@","]];
                }
                else{
                    keyStr=[NSString stringWithFormat:@"%@&%@=%@",keyStr,str,[dict valueForKey:str]];
                }
                
            }
            
        }
    }
    if(keyStr.length<=0)
    {
        keyStr=@"";
    }
    //1..检查网络连接(苹果公司提供的检查网络的第三方库 Reachability)
    //AFN 在 Reachability基础上做了一个自己的网络检查的库, 基本上一样
    
    if (isFirst == NO)
    {
        //网络只有在startMonitoring完成后才可以使用检查网络状态
        [[AFNetworkReachabilityManager sharedManager] startMonitoring];
        [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            canCHeckNetwork = YES;
        }];
        isFirst = YES;
    }
    AppDelegate *app=(AppDelegate*)[UIApplication sharedApplication].delegate;
    //只能在监听完善之后才可以调用
    BOOL isOK = [[AFNetworkReachabilityManager sharedManager] isReachable];
    //BOOL isWifiOK = [[AFNetworkReachabilityManager sharedManager] isReachableViaWiFi];
    //BOOL is3GOK = [[AFNetworkReachabilityManager sharedManager]isReachableViaWWAN];
    //网络有问题
    if(isOK == NO && canCHeckNetwork == YES)
    {
//        NSError *error = [NSError errorWithDomain:@"网络错位" code:100 userInfo:nil];
//        back(nil, nil,error);
        
        [[NetworkingViewController sharedController ] dismissNetworking];
        
        
        [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"网络异常" andWithCancel:@"确认"];
        
        return;
    }
    
    //2..实现解析
    NSString *urlpath=[[NSString stringWithFormat:@"http://%@/INFO_DMS_WEB/AjaxChannel?action=%@%@",MyIP,actionStr,keyStr]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSLog(@"posturl=%@",urlpath);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.responseSerializer.acceptableContentTypes setByAddingObject:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", nil]];
    
//    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded"  forHTTPHeaderField:@"Content-Type"];
    [manager POST:urlpath parameters:dict success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //成功 back是对方传递过来的对象 这里是直接调用
        NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        back(responseObject, obj ,nil);
        if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"])
        {
            //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"当前账号已经在其他设备上登录,请重新登录" andWithCancel:@"确认"];
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"当前账号已经在其他设备上登录,请重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                alert.tag = 9998;
                [alert show];
            });
        }
        else
            if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"])
        {

            [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];

        }
            else
                if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1400"])
                {
                    
                    //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",@"抱歉，会话超时,请您注销并重新登录"] andWithCancel:@"确认"];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉，会话超时,请您注销并重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                        alert.tag = 9999;
                        [alert show];
                    });
                }
                else
                    if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"MSG_ERROR_SAVE"])
                    {
                        
                       [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];
                        
                    }
                    else
                        if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"MSG_ASC_USER_NOT_FOUND"])
                        {
                            
                            [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];
                            
                        }
                        else
                            if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"MSG_ASC_PASSWORD_WRONG"])
                            {
                                
                                [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];
                                
                            }
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error)
    {
        //失败
        back(nil, nil ,error);
        [SVProgressHUD dismiss];
        NSLog(@"失败");
    }];
};


+(void) getWithAction:(NSString*)actionStr andipstr:(NSString*)myip finish:(void (^)(NSData *,NSDictionary *obj, NSError *))back{
    //数据拼接
    
    //1..检查网络连接(苹果公司提供的检查网络的第三方库 Reachability)
    //AFN 在 Reachability基础上做了一个自己的网络检查的库, 基本上一样
    
    if (isFirst == NO) {
        //网络只有在startMonitoring完成后才可以使用检查网络状态
        [[AFNetworkReachabilityManager sharedManager] startMonitoring];
        [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            canCHeckNetwork = YES;
        }];
        isFirst = YES;
    }
    
    //只能在监听完善之后才可以调用
    BOOL isOK = [[AFNetworkReachabilityManager sharedManager] isReachable];
    //BOOL isWifiOK = [[AFNetworkReachabilityManager sharedManager] isReachableViaWiFi];
    //BOOL is3GOK = [[AFNetworkReachabilityManager sharedManager]isReachableViaWWAN];
    //网络有问题
    if(isOK == NO && canCHeckNetwork == YES){
        NSError *error = [NSError errorWithDomain:@"网络错位" code:100 userInfo:nil];
        back(nil, nil,error);
        return;
    }
    
    //2..实现解析
    NSString *urlpath=[NSString stringWithFormat:@"http://%@/INFO_DMS_WEB/AjaxChannel?action=%@&ENTITY_CODE=GLOBAL",myip,actionStr];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:urlpath parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        //成功 back是对方传递过来的对象 这里是直接调用
        NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        back(responseObject, obj ,nil);
        
        if([[obj objectForKey:@"SUCCESS"]integerValue]==0)
        {
            
                AppDelegate *app=(AppDelegate*)[UIApplication sharedApplication].delegate;
            [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"IP设置失败" andWithCancel:@"确定"];
           
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD dismiss];

        AppDelegate *app=(AppDelegate*)[UIApplication sharedApplication].delegate;
        [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"IP设置失败" andWithCancel:@"确定"];
        //失败
        back(nil, nil ,error);
    }];
};



+(void)getWithAction:(NSString *)actionStr andParam:(NSDictionary *)dic andarr:(NSMutableArray *)ImageDataArr finish:(void (^)(NSData *, NSDictionary *, NSError *))back
{
    //数据拼接
    NSArray *keyArr=[dic allKeys];
    NSString *keyStr;
    
    if([keyArr count]>0)
    {
        for(NSString *str in keyArr)
        {
            if(keyStr.length<=0)
            {
                keyStr=[NSString stringWithFormat:@"&%@=%@",str,[dic valueForKey:str]];
            }
            else
            {
                keyStr=[NSString stringWithFormat:@"%@&%@=%@",keyStr,str,[dic valueForKey:str]];
            }
        }
    }
    if(keyStr.length<=0)
    {
        keyStr=@"";
    }
    //1..检查网络连接(苹果公司提供的检查网络的第三方库 Reachability)
    //AFN 在 Reachability基础上做了一个自己的网络检查的库, 基本上一样
    
    if (isFirst == NO) {
        //网络只有在startMonitoring完成后才可以使用检查网络状态
        [[AFNetworkReachabilityManager sharedManager] startMonitoring];
        [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            canCHeckNetwork = YES;
        }];
        isFirst = YES;
    }
    
    //只能在监听完善之后才可以调用
    BOOL isOK = [[AFNetworkReachabilityManager sharedManager] isReachable];
    //BOOL isWifiOK = [[AFNetworkReachabilityManager sharedManager] isReachableViaWiFi];
    //BOOL is3GOK = [[AFNetworkReachabilityManager sharedManager]isReachableViaWWAN];
    //网络有问题
    if(isOK == NO && canCHeckNetwork == YES)
    {
        NSError *error = [NSError errorWithDomain:@"网络错位" code:100 userInfo:nil];
        back(nil, nil,error);
        return;
    }
    

    //2..实现解析
    NSString *urlpath=[[NSString stringWithFormat:@"http://%@/INFO_DMS_WEB/AjaxChannel?action=%@%@",MyIP,actionStr,keyStr]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:urlpath parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
    {
        for (int i = 0; i <ImageDataArr.count; i++)
        {
            // 上传的参数名
            NSString * Name = [NSString stringWithFormat:@"%@%d", @"attch",i];
            
            // 上传filename
            NSString * fileName = [NSString stringWithFormat:@"%@.jpg", Name];
            
            NSData *imageData = [ImageDataArr objectAtIndex:i];
            
            [formData appendPartWithFileData:imageData name:Name fileName:fileName mimeType:@"image/jpg"];
        }
        
    } success:^(NSURLSessionDataTask *task, id responseObject)
    {
        
        //成功 back是对方传递过来的对象 这里是直接调用
        NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"sucess");
        
        AppDelegate *app=(AppDelegate*)[UIApplication sharedApplication].delegate;
        
        if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"])
        {
            //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"当前账号已经在其他设备上登录,请重新登录" andWithCancel:@"确认"];
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"当前账号已经在其他设备上登录,请重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                alert.tag = 9998;
                [alert show];
            });
        }
        else
            if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"]==NO)
            {
                
                [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];
            }
        
            else
                if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1400"])
                {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉，会话超时,请您注销并重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                        alert.tag = 9999;
                        [alert show];
                    });
                    //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",@"抱歉，会话超时,请您注销并重新登录"] andWithCancel:@"确认"];
                    
                }
        back(responseObject, obj ,nil); 
        
    }
          failure:^(NSURLSessionDataTask *task,NSError *error)
    {
        [SVProgressHUD dismiss];

        NSLog(@"%@",error);
    }];
}



+(void)postWithParam:(NSMutableArray *)iamgeArr mainImage:(NSMutableArray *)mainImageArr parameters:(NSDictionary *)PostDic  andActionString:(NSString *)actionStr  finish:(void (^)(NSData *, NSDictionary *, NSError *))back
{
//    NSLog(@"+++++++++++++++%@",iamgeArr);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.responseSerializer.acceptableContentTypes setByAddingObject:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", nil]];
    
    NSString *urlpath=[[NSString stringWithFormat:@"http://%@/INFO_DMS_WEB/HttpChannel?action=%@",MyIP,actionStr]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSLog(@"%@",urlpath);

    
    // 显示进度
    [manager POST:urlpath parameters:PostDic constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
     {
         // 上传 多张图片
         for(NSInteger i = 0; i < iamgeArr.count; i++)
         {
             NSData * imageData = [iamgeArr objectAtIndex: i];
             
             // 上传的参数名
             NSString * Name = [NSString stringWithFormat:@"%@", @"attch"];
             
             
             NSString  *fileName=[NSString stringWithFormat:@"File%ld.jpg",(long)i];

             [formData appendPartWithFileData:imageData name:Name fileName:fileName mimeType:@"image/jpg"];
         }
         
//         [formData appendPartWithFileData:[mainImageArr objectAtIndex:0] name:@"attch" fileName:@"mainImage" mimeType:@"image/jpg"];
     }
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSString *str1 = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
         
         //把NSdata转为为NSString
         
         NSLog(@"%@",str1);
         
         //成功 back是对方传递过来的对象 这里是直接调用
         NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
         
         NSLog(@"上传图片成功sucess %@",obj);
         
         AppDelegate *app=(AppDelegate*)[UIApplication sharedApplication].delegate;
         
         if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"])
         {
             //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"当前账号已经在其他设备上登录,请重新登录" andWithCancel:@"确认"];
             dispatch_async(dispatch_get_main_queue(), ^{
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"当前账号已经在其他设备上登录,请重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                 alert.tag = 9998;
                 [alert show];
             });
         }
         else
             if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"]==NO)
             {
//                 [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];
             }
             else
                 if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1400"])
                 {
                     dispatch_async(dispatch_get_main_queue(), ^{
                         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉，会话超时,请您注销并重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                         alert.tag = 9999;
                         [alert show];
                     });
                     //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",@"抱歉，会话超时,请您注销并重新登录"] andWithCancel:@"确认"];
                 }
         back(responseObject, obj ,nil);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [SVProgressHUD dismiss];
         NSLog(@"返回出错%@",error);
     }];
}


+(void)postWithParamImage:(NSData *)mainImageData parameters:(NSDictionary *)PostDic  andActionString:(NSString *)actionStr  finish:(void (^)(NSData *, NSDictionary *, NSError *))back
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.responseSerializer.acceptableContentTypes setByAddingObject:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", nil]];
    
    NSString *urlpath=[[NSString stringWithFormat:@"http://%@/INFO_DMS_WEB/HttpChannel?action=%@",MyIP,actionStr]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    // 显示进度
    [manager POST:urlpath parameters:PostDic constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
     {
        // 上传的参数名
        NSString * Name = [NSString stringWithFormat:@"%@", @"attch"];
         
        NSString  *fileName=[NSString stringWithFormat:@"sign"];
             
        [formData appendPartWithFileData:mainImageData name:Name fileName:fileName mimeType:@"image/jpg"];
     }
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         //成功 back是对方传递过来的对象 这里是直接调用
         NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
         
         NSLog(@"上传图片成功sucess %@",obj);
         
         AppDelegate *app=(AppDelegate*)[UIApplication sharedApplication].delegate;
         
         if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"])
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"当前账号已经在其他设备上登录,请重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                 alert.tag = 9998;
                 [alert show];
             });
             //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:@"当前账号已经在其他设备上登录,请重新登录" andWithCancel:@"确认"];
         }
         else
             if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1402"]==NO)
             {
                 [UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",[obj valueForKey:@"MSG"]] andWithCancel:@"确认"];
             }
             else
                 if ([[obj valueForKey:@"SUCCESS"]integerValue]==0&&[[obj valueForKey:@"MSGCODE"]isEqualToString:@"EC-FRM-1400"])
                 {
                     dispatch_async(dispatch_get_main_queue(), ^{
                         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉，会话超时,请您注销并重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新连接",nil];
                         alert.tag = 9999;
                         [alert show];
                     });
                     //[UIAlertViewControl showAlertView:app.window.rootViewController WithMes:[NSString stringWithFormat:@"%@",@"抱歉，会话超时,请您注销并重新登录"] andWithCancel:@"确认"];
                 }
         back(responseObject, obj ,nil);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [SVProgressHUD dismiss];

         back(nil, nil ,error);
         NSLog(@"返回出错%@",error);
     }];
}

+(void)postWithParam:(NSDictionary *)dict imageArr:(NSArray *)imageArr andAction:(NSString *)actionStr finish:(void (^)(NSData *, NSDictionary *, NSError *))back{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.responseSerializer.acceptableContentTypes setByAddingObject:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", nil]];
    
    NSString *urlpath=[[NSString stringWithFormat:@"http://%@/INFO_DMS_WEB/HttpChannel?action=%@",MyIP,actionStr]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    [manager POST:urlpath parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //成功 back是对方传递过来的对象 这里是直接调用
        NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        back(responseObject, obj ,nil);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [SVProgressHUD dismiss];

        back(nil, nil ,error);
        NSLog(@"返回出错%@",error);
    }];
}

#pragma mark - alertDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex!=0) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"connetLogin" object:nil];
        
        
    }
}

@end
